package org.sunflower.aliyun.ice;

import com.aliyun.ice20201109.Client;
import com.aliyun.teaopenapi.models.Config;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.sunflower.aliyun.AliyunProperties;

/**
 * @description:
 * @author: TanJingyu
 * @create: 2021-10-11 19:18
 **/
@Configuration
@EnableConfigurationProperties(value = AliyunProperties.Ice.class)
@RequiredArgsConstructor
@Slf4j
public class IceConfiguration {
    private final AliyunProperties.Ice properties;

    @Bean
    public Client aliyunIceClient() throws Exception {
        Config config = new Config().setAccessKeyId(properties.getAccessKeyId())
                .setAccessKeySecret(properties.getAccessKeySecret())
                .setEndpoint(properties.getEndpoint())
                .setRegionId(properties.getRegionId());
//                .setConnectTimeout()
//                .setReadTimeout()


        Client client = null;
        try {
            client = new Client(config);
        } catch (Exception e) {
            log.error("配置阿里云Ice失败！errorMsg:{}", e.getMessage());
            throw e;
        }

        return client;
    }
}
